<template>
  <div class="app-container">
    <table-com :cols="cols" :table-data="tableData"></table-com>
    <Pagination
      v-if="page.total"
      :total="page.total"
      :page.sync="page.pageNum"
      :limit.sync="page.pageSize"
      @pagination="fetchData"
    />
  </div>
</template>

<script>
  import Pagination from '@/components/Pagination'
  import TableCom from '@/components/Table'
  import { getFeedbackList } from '@/api/feedback'
  import { parseTime } from '@/utils/index'
  export default {
    components: { TableCom, Pagination },
    data() {
      return {
        cols: [
          {
            label: 'openId',
            key: 'openId'
          },
          {
            label: '反馈内容',
            key: 'content'
          },
          {
            label: '联系方式',
            key: 'contact'
          },
          {
            label: '反馈时间',
            key: 'createTime',
            format(row) {
              if (row.createTime) {
                return parseTime(row.createTime)
              }
              return ''
            }
          }
        ],
        tableData: [],
        page: {
          total: 0,
          pageNum: 1,
          pageSize: 20
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      async fetchData() {
        const { pageNum, pageSize } = this.page
        this.page.total = 0
        const parmas = {
          pageNum,
          pageSize
        }
        const res = await getFeedbackList(parmas)
        const { data } = res
        this.tableData = data.list
        this.page.total = data.total
      }
    }
  }
</script>
